/**
* @Title: caseHandle_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
* Company:中国平安
* ex-xieqi001
* @Project HIMS-FWA
* @date 2014年11月11日 下午4:43:38
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('AuditPostCtrl', ['$scope','$stateParams','CommunityService','BaseURL','Modal','AuditPostService',
	                                function($scope,$stateParams,CommunityService,baseUrl,Modal,AuditPostService){
		//待分配调查事件
		$scope.investigated = {
				include: baseUrl + 'views/hcpms/workingArea/audit/auditPost/distributionInvestigated_view.html'
		};
		// 待分配稽核任务
		$scope.distributionAudit = {
				include: baseUrl + 'views/hcpms/workingArea/audit/auditPost/distributionAuditTask_view.html'
		}; 
		//待审核调查事件
		$scope.pendingInvestigation = {
				include: baseUrl + 'views/hcpms/workingArea/audit/auditPost/pendingAuditInvestigation_view.html'
		}; 
		//待审核稽核任务
		$scope.pendingAudit = {
				include: baseUrl + 'views/hcpms/workingArea/audit/auditPost/pendingAuditAudit_view.html'
		}; 
        
		//获取待审核事件的数量以及显示进度条长度
		AuditPostService.getPendingAudit().success(function(res){
			//判断最大值为100% 其他占比是占最大值的百分之多少
			var value = CommunityService.compareValue(res.investigatedNum,res.distributionAuditNum);
			
			var value2 = CommunityService.compareValue(res.pendingInvestigationNum,res.pendingAuditNum);
			
			var num =  CommunityService.compareValue(value,value2);
			
			$scope.investigated.proportion = (res.investigatedNum/num)*100;
			$scope.distributionAudit.proportion = (res.distributionAuditNum/num)*100;
			$scope.pendingInvestigation.proportion = (res.pendingInvestigationNum/num)*100;
			$scope.pendingAudit.proportion = (res.pendingAuditNum/num)*100;
			
			$scope.investigated.num = res.investigatedNum;
			$scope.distributionAudit.num = res.distributionAuditNum;
			$scope.pendingInvestigation.num = res.pendingInvestigationNum;
			$scope.pendingAudit.num = res.pendingAuditNum;
		});
		
		$scope.barOption = {
				title:{
					text: '事件案件汇总',
			        x: 'left'
				},
				grid:{
					x:30,
					y:40,
					x2:10,
					y2:40,
					borderColor:'#fff'
				},
				xAxis : [{
		             type : 'category',
		             boundaryGap: true,
		             data : ['14-01']
		         }],
		         series:[],
		         color:['#56C8E3','#F4AF74']
		};
		//获取echarts 数据
		AuditPostService.getQuestionCount().success(function(res){
			
			$scope.barOption.xAxis = [{
	             type : 'category',
	             boundaryGap: true,
	             data : res.dateList
	         }];
			
			var barSeries  = [];
			barSeries.push({
				name:'事件调查',
				type:'bar',
				data:res.investigatedData
			},{
				name:'稽核案件',
				type:'bar',
				data:res.auditData
			});
			$scope.barOption.series = barSeries; 
		});
		
		//选中div
		$scope.selectedDiv = function (selected){
			$scope.selected = selected;
		}
		
		//默认选中一个div
		if ($stateParams.urlFlag) {
			if ($stateParams.urlFlag == '1') {
				$scope.selected = $scope.distributionAudit;
			}
			else if ($stateParams.urlFlag == '6') {
				$scope.selected = $scope.pendingInvestigation;
			}else if ($stateParams.urlFlag == '4') {
				$scope.selected = $scope.pendingAudit;
			}
			else {
				$scope.selected = $scope.investigated;
			}
		}
		else {
			$scope.selected = $scope.investigated;
		}
	
	}]).controller('DistributionInvestigatedCtrl', ['$scope','FwaTabsetService','Modal','AuditPostService',
	                               function($scope,FwaTabsetService,Modal,AuditPostService){
		$scope.columns = [
			      			{
			    				label : '事件号',
			    				map : 'problemNo',
			    				width : '10%',
			    				cellTemplate:'<a  ng:bind="data.problemNo" ng-click="queryByProblemNo(data)"></a>'
			    			},{
			    				label : '事件时间段',
			    				map : 'periodDate',
			    				width : '15%'
			    			}, {
			    				label : '事件要点',
			    				map : 'keyPoint',
			    				width : '20%'
			    			}, {
			    				label : '来源方式',
			    				map : 'sourceTypeDesc',
			    				width : '10%'
			    			}, {
			    				label : '提交日期',
			    				map : 'submitDate',
			    				width : '15%'
			    			}, {
			    				label : '关联案件号',
			    				map : 'caseCode',
			    				width : '10%'
			    			}, {
			    				label : '状态',
			    				map : 'statusName',
			    				width : '10%'
			    			}, {
			    				label : '操作',
			    				map : 'operations',
			    				width : '10%',
			    				cellClass:'text-center',
			    				cellTemplate:'<a  ng-click="operation(data)">审核</a>'
			    			}
			    		];
		
		var code = '3';
		//查询
		function query() {
			AuditPostService.queryProblemTaskList(code).success(function(res){
				if (res) {
	        		$scope.tableData = res.result;
	        		$scope.totalCount = res.total;
	    		}
			});
		}
		query();
		
		//查看
		$scope.queryByProblemNo = function(data) {
			FwaTabsetService.selectTab('problemDetailView.detail',{problemCode:data.problemNo,problemStatus:data.problemStatus},false);
		}
		
		//事件分配
		$scope.operation = function(data){
			FwaTabsetService.selectTab('problemCheck.auditFindDispatch',{problemNo:data.problemNo,urlFlag:code},false);
		}
	
	}]).controller('DistributionAuditTaskCtrl', ['$scope','FwaTabsetService','Modal','AuditPostService',
	                               function($scope,FwaTabsetService,Modal,AuditPostService){
		$scope.columns = [
			          		{
			          			label : '案件号',
			          			map : 'caseCode',
			          			width : '10%',
			          			 cellTemplate:'<a  ng:bind="data.caseCode" ng-click="queryByProblemNo(data)"></a>'},
			          		{
			          			label : '机构名称',
			          			map : 'orgName',
			          			width : '15%'
			          		}, {
			          			label : '受理时间',
			          			map : 'auditDate',
			          			width : '17%'
			          		}, {
			          			label : '不合理费用',
			          			map : 'totalDeduction',
			          			width : '10%'
			          		}, {
			          			label : '告知时间',
			          			map : 'notifyDate',
			          			width : '15%'
			          		}, {
			          			label : '机构确认时间',
			          			map : 'affirmDate',
			          			width : '15%'
			          		}, {
			          			label : '案件状态',
			          			map : 'statusName',
			          			width : '10%'
			          		}, {
			          			label : '操作',
			          			map : 'operation',
			          			width : '8%',
			          			cellClass:'text-center',
			          			cellTemplate:'<a  ng-click="operation(data);">审核</a>'
			          		}
			          	];
		var code = '1';
		//查询
		function query() {
			AuditPostService.queryCaseTaskList(code).success(function(res){
				if (res) {
	        		$scope.tableData = res.result;
	        		$scope.totalCount = res.total;
	    		}
			});
		}
		query();
		
		//查看
		$scope.queryByProblemNo = function(data) {
			FwaTabsetService.selectTab('caseDetailView.detail',{problemCode:data.relatedCode,caseCode:data.caseCode},false);
		}
		
		//分配
		$scope.operation = function(data){
//			FwaTabsetService.selectTab('caseAuditProject',{caseCode:data.caseCode,problemNo:data.relatedCode,urlFlag:code},false);
		}
	
	}]).controller('PendingAuditInvestigation', ['$scope','FwaTabsetService','Modal','AuditPostService',
	                               function($scope,FwaTabsetService,Modal,AuditPostService){
		$scope.columns = [
			      			{
			    				label : '事件号',
			    				map : 'problemNo',
			    				width : '10%',
			    				cellTemplate:'<a  ng:bind="data.problemNo" ng-click="queryByProblemNo(data)"></a>'
			    			},{
			    				label : '事件时间段',
			    				map : 'periodDate',
			    				width : '15%'
			    			}, {
			    				label : '事件要点',
			    				map : 'keyPoint',
			    				width : '20%'
			    			}, {
			    				label : '来源方式',
			    				map : 'sourceTypeDesc',
			    				width : '10%'
			    			}, {
			    				label : '提交日期',
			    				map : 'submitDate',
			    				width : '15%'
			    			}, {
			    				label : '关联案件号',
			    				map : 'caseCode',
			    				width : '10%'
			    			}, {
			    				label : '状态',
			    				map : 'statusName',
			    				width : '10%'
			    			}, {
			    				label : '操作',
			    				map : 'operations',
			    				width : '10%',
			    				cellClass:'text-center',
			    				cellTemplate:'<a  ng-click="operation(data)">审核</a>'
			    			}
			    		];
		
		var code = '6';
		//查询
		function query() {
			AuditPostService.queryProblemTaskList(code).success(function(res){
				if (res) {
	        		$scope.tableData = res.result;
	        		$scope.totalCount = res.total;
	    		}
			});
		}
		query();
		
		//查看
		$scope.queryByProblemNo = function(data) {
			FwaTabsetService.selectTab('problemCheck.auditFindDispatch',{problemNo:data.problemNo},false);
		}
		
		//调查事件审核
		$scope.operation = function(data){
			FwaTabsetService.selectTab('researchCheck.researchConclusionCheck',{problemNo:data.problemNo,urlFlag:code},false);
		}
	
	}]).controller('PendingAuditAuditCtrl', ['$scope','FwaTabsetService','Modal','AuditPostService',
	                               function($scope,FwaTabsetService,Modal,AuditPostService){
		$scope.columns = [
			          		{
			          			label : '案件号',
			          			map : 'caseCode',
			          			width : '10%',
			          			 cellTemplate:'<a  ng:bind="data.caseCode" ng-click="queryByProblemNo(data)"></a>'},
			          		{
			          			label : '机构名称',
			          			map : 'orgName',
			          			width : '15%'
			          		}, {
			          			label : '受理时间',
			          			map : 'auditDate',
			          			width : '17%'
			          		}, {
			          			label : '不合理费用',
			          			map : 'totalDeduction',
			          			width : '10%'
			          		}, {
			          			label : '告知时间',
			          			map : 'notifyDate',
			          			width : '15%'
			          		}, {
			          			label : '机构确认时间',
			          			map : 'affirmDate',
			          			width : '15%'
			          		}, {
			          			label : '案件状态',
			          			map : 'statusName',
			          			width : '10%'
			          		}, {
			          			label : '操作',
			          			map : 'operation',
			          			width : '8%',
			          			cellClass:'text-center',
			          			cellTemplate:'<a  ng-click="operation(data);">审核</a>'
			          		}
			          	];
		var code = '4';
		//查询
		function query() {
			AuditPostService.queryCaseTaskList(code).success(function(res){
				if (res) {
	        		$scope.tableData = res.result;
	        		$scope.totalCount = res.total;
	    		}
			});
		}
		query();
		
		//查看
		$scope.queryByProblemNo = function(data) {
			FwaTabsetService.selectTab('caseDetailView.detail',{problemCode:data.relatedCode,caseCode:data.caseCode},false);
		}
		
		//审核
		$scope.operation = function(data){
			FwaTabsetService.selectTab('caseCheck.caseCheckProcessList',{caseCode:data.caseCode,problemCode:data.relatedCode,urlFlag:code},false);
		}
	
	}]);
})();
